package gek.uni.diplom.ocl.example.patterns.hierarhical;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class CodeCompleter {

  public static Set<String> collectImportString(IPattern rootPattern) {
    Set<String> resultSet = new HashSet<String>();

    Collection<String> importStrings = rootPattern.getImportStrings();
    if (importStrings != null)
      resultSet.addAll(rootPattern.getImportStrings());

    for (IPattern child : rootPattern.getChildren()) {
      resultSet.addAll(CodeCompleter.collectImportString(child));
    }

    return resultSet;
  }
  
  public static Collection<String> collectDeclareCode(IPattern rootPattern){
    
    List<String> result = new ArrayList<String>();
    
    for (IPattern child: rootPattern.getChildren()){
      result.addAll(collectDeclareCode(child));
    }
    
    if (rootPattern instanceof VariableExpCodeNode){
      result.add(((AChangeableCodeNode) rootPattern).getDeclarationString());
      result.add(((AChangeableCodeNode) rootPattern).getGetterInitString());
    }
    
//    if (rootPattern instanceof FeatureCallPattern){
//      result.add(((FeatureCallPattern) rootPattern).getDeclareSection());
//      result.add(((FeatureCallPattern) rootPattern).getGetterInitString());
//    }
    return result;
  }
  
  public static Collection<String> collectTestCode(IPattern rootPattern){
    List<String> result = new ArrayList<String>();
    result.addAll(collectDeclareCode(rootPattern));
    
    if (rootPattern instanceof BooleanExpCodeNode)
      result.add(((BooleanExpCodeNode) rootPattern).getTrueSection());
    
    return result;
  }  
}
